//
//  PywBindSetPwdApi.m
//  PywSdk
//
//  Created by Jade on 16/8/31.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "PywBindSetPwdApi.h"
#import "AiFPassportRegAndBindAccountManager.h"
#import "PropertyListReformer.h"
#import "PywMBProgressHUD+Pyw.h"

@interface PywBindSetPwdApi()<ETAPIManagerCallBackDelegate>

@end
@implementation PywBindSetPwdApi
/**
 *  绑定-设置通行证密码
 *
 *  @param success <#success description#>
 *  @param fail    <#fail description#>
 */
- (void)requestBindSetPwdWithPassport:(NSString *)passport
                             password:(NSString *)password
                            success:(Successd)success
                               fail:(Failure)fail
{
    self.successd = success;
    self.failure = fail;
    [PywMBProgressHUD showMessage:@"正在绑定..."];
    AiFPassportRegAndBindAccountManager *manager = [AiFPassportRegAndBindAccountManager manager];
    manager.delegate = self;
    manager.passport = passport;
    manager.passport_pwd = password;
    [manager loadData];
}

- (void)managerCallAPIDidSuccess:(ETApiBaseManager *)manager
{
    [PywMBProgressHUD hideHUD];
    PropertyListReformer *reformer = [[PropertyListReformer alloc] init];
    NSDictionary *dict = [manager fetchDataWithReformer:reformer];
    NSInteger ack = [[dict objectForKey:@"ack"] integerValue];
    if (ack == 200) {
        if (self.successd) {
            self.successd(nil,[dict objectForKey:@"data"]);
        }
    }else {
        NSString *msg = [dict objectForKey:@"msg"];
        [PywMBProgressHUD showError:msg];
        if (self.failure) {
            self.failure([self errorWithCode:ack]);
        }
    }
}
- (void)managerCallApiDidFailed:(ETApiBaseManager *)manager
{
    [PywMBProgressHUD hideHUD];
    if (self.failure) {
        self.failure([self errorWithCode:0]);
    }
    
}
@end
